import numpy as np

def restore(file_path, file_format):
    read_func = {
        'npy': lambda path: np.load(path),
        'txt': lambda path: np.loadtxt(path),
        'csv': lambda path: np.genfromtxt(path, delimiter=',')
    }
    
    if file_format not in read_func:
        print("Unsupported file format.")
        return None
    
    try:
        data = read_func[file_format](file_path)
        return data
    except Exception as e:
        print(f"Error occurred while reading the file: {e}")
        return None

# 示例用法
npy_data = restore('data.npy', 'npy')
txt_data = restore('data.txt', 'txt')
csv_data = restore('data.csv', 'csv')

print("npy data:")
print(npy_data)

print("txt data:")
print(txt_data)

print("csv data:")
print(csv_data)
